
#ifndef _PLAYER_H_
#define _PLAYER_H_

#include <math.h>

#include "common.h"

// 0.1 = move 1/10th foot with each call to move*()
// 1.0 = move one foot with each call to move*()
// 10.0 = move ten feet with each call to move*()
#define MOVE_UNIT_INCR 0.1

__BEGIN_NAMESPACE_DECL_

/**
 * Class that represents a player, their position in 3D space,
 * and the orientation in which they are looking. 
 */
class Player
{
    public:
        // Constructor & Destructor
        Player();

        // Resets the players mutable state
        void reset ();
        // Member modification functions
        void setUnitsPerFoot (double unitsPerFoot);
        // Sets the players position
        void setPosition  (double xpos, double ypos, double zpos);
        void setViewAngle (double viewAngle) { _viewAngle = viewAngle; }
        void setPitch     (double pitch) { _pitch = pitch; }
        // Moves the player forward by a constant factor
        void moveForward ();
        // Moves the player backward by a constant factor
        void moveBackward ();
        // Moves the player left by a constant factor
        void moveLeft ();
        // Moves the player left by a constant factor
        void moveRight ();

        // changes angle of player's view
        void lookLeft(double factor=1.0)  { _viewAngle += 0.1 * factor; }
        void lookRight(double factor=1.0) { _viewAngle -= 0.1 * factor; }
        void lookUp(double factor=1.0)    { _pitch += 0.1 * factor; }
        void lookDown(double factor=1.0)  { _pitch -= 0.1 * factor; }

        // Constant member functions
        // Retrieve the players position
        void getPosition (double& xpos, double& ypos, double& zpos) const;

        // Retrieves the players viewing angle in degrees
        double getViewAngle () const { return _viewAngle; }
        double getPitch () const     { return _pitch; }

    // Member variables
    protected:
        // Player position 
        double _xpos;
        double _ypos;
        double _zpos;
        // Angle of rotation around vertical axis (where the player is looking)
        double _viewAngle;
        // Angle of rotation around horizontal axis (player looking up/down)
        double _pitch;
        // Angle and bias used to modify the players vertical position (height)
        // as they walk.  This makes moving forward/backward feel more realistic
        double _bobAngle;
        double _bias;
        double _unitsPerFoot;
};

__END_NAMESPACE_DECL_

#endif

